#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstdbool>
#include <cstring>
#include <unistd.h>
#include <ctime>
#include <sys/shm.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/stat.h>
#include <fcntl.h>

using namespace std;

#define PATH_NAME "/home/yx"
#define PROJ_ID 333
#define FILE_MODE 0666
#define IPC_SIZE 4096

// 1，共享内存是所有ipc中速度最快的
// 2，共享内存是访问不受控制的

// 通过命名管道间接让共享内存访问受控制

#define FIFO_PATH "./fifo.ipc"

class InitFIFO
{
public:
    InitFIFO()
    {
        umask(0000);

        int n=mkfifo(FIFO_PATH,FILE_MODE);
        assert(n==0);
        (void)n;

    }
    
    ~InitFIFO()
    {
        int n=unlink(FIFO_PATH);
        assert(n==0);
        (void)n;
    }
};

#define READ O_RDONLY
#define WRITE O_WRONLY

int OpenFIFO(const char* path,int flags)
{
    int fd=open(path,flags);
    assert(fd>=0);

    return fd;
}

void CloseFIFO(int fd)
{
    assert(close(fd)!=-1);
}

void Wait(int fd)
{   
    uint32_t mark=1;

    ssize_t n=read(fd,&mark,sizeof(mark));
    assert(n==4);
    (void)n;

}

void Signal(int fd)
{
    uint32_t mark=1;
    ssize_t n=write(fd,&mark,sizeof(mark));
    assert(n==4);
    (void)n;
}
